
<template>
<div class="card">
    <!-- 头部 -->
    <div class="header">
        <div class="index-header">
            <div class="location" @click="getLocation">
                <!-- 纬度: {{ location.latitude }},经度: {{ location.longitude }} -->
                <img src="../../assets/icons/svg/map-point.svg" alt="定位" />
                <label>{{ truncateText("广州番禺节能科技园", 12) }} ❯ </label>
            </div>
            <div class="head-bar">
                <span><img src="../../assets/icons/svg/customer-service.svg" alt="客服" @click="serviceChat" /></span>
                <span @click="mallCar">
                    <img src="../../assets/icons/svg/shopping-cart.svg" alt="购物车" />
                    <label v-if="carNumber > 0" class="car-number">{{ carNumber }}</label>
                </span>
                <span><img src="../../assets/icons/svg/more.svg" alt="更多" @click="moreFlag=true" /></span>
            </div>
        </div>

        <!-- 搜索 -->
        <div class="search-container">
            <button class="scan-btn" @click="searchScan">
                <img src="../../assets/icons/qr-code.png" />
            </button>
            <label style="color: #ccc">| </label>
            <input type="text" class="search-input" placeholder="手表" @click="searchInput" />
            <button class="search-btn" type="button" @click="searchBtn">
                搜索
            </button>
        </div>
    </div>

    <!-- 菜单 -->
    <div class="menu">
        <div class="menu-container" v-for="(menu, index) in menuTypes" :key="index" @click="jumpType(menu)">
            <img :src="menu.typeIcon" class="menu-image" />
            <div class="menu-content">{{ menu.typeName }}</div>
        </div>
    </div>

    <!--轮播和热门-->
    <div class="adver">
        <!-- 轮播 -->
        <div class="lunbo">
            <div class="carousel-container"
                @touchstart="handleTouchStart"
                @touchmove="handleTouchMove"
                @touchend="handleTouchEnd"
                @mousedown="handleTouchStart"
                @mousemove="handleTouchMove"
                @mouseup="handleTouchEnd">
                <div class="carousel" :style="{ transform: `translateX(-${currentIndex * 100}%)` }">
                    <img v-for="(image, index) in images" :key="index" :alt="image.remark" :src="image.src" @click="carousel(image)" />
                </div>
                <div class="dots">
                    <span v-for="(dot, index) in totalImages" :key="index" @click="setCurrentIndex(index)" :class="{ active: index === currentIndex }"></span>
                </div>
            </div>
        </div>
        <!-- 甄选与活动 -->
        <div class="huodong">
            <div class="zhenxuan">
                <img :src="zhenxuan.src" :alt="haowu.remark" @click="zhenxuanFun(zhenxuan)"/>
            </div>
            <div class="haowu">
                <img :src="haowu.src" :alt="haowu.remark" @click="haowuFun(haowu)" />
            </div>
        </div>
    </div>

    <!-- 精选优品与生活百货-->
    <div class="life">
        <div class="jingxuan">
            <router-link :to="{ name: jingxuan.routeName, params: { moduleId: 1233, moduleName: '精选优品' }}">
                <img :src="jingxuan.src" :alt="jingxuan.remark"/>
            </router-link>
        </div>
        <div class="shenghuo">
            <router-link :to="{ name: shenghuo.routeName, params: { moduleId: 1234, moduleName: '生活百货' }}">
                <img :src="shenghuo.src" :alt="shenghuo.remark" />
            </router-link>
        </div>
    </div>

    <!-- 导航标题-->
    <div class="shop-nav">
        <div class="shop-title">
            <div class="clickable" tabindex="0" role="button" @click="selectedChecked('精品优选')">
                <strong>精品优选</strong>
                <div :class="{'selected-indicator': selectedIndicator === '精品优选'}"></div>
            </div>
            <div class="clickable" tabindex="0" role="button" @click="selectedChecked('生活百货')">
                <strong>生活百货</strong>
                <div :class="{'selected-indicator': selectedIndicator === '生活百货'}"></div>
            </div>
        </div>
    </div>

    <div v-if="selectedIndicator === '精品优选'">
        <ShopColumnList :dataList="dataList" />
    </div>
    <div v-if="selectedIndicator === '生活百货'">
        <ShopColumnList :dataList="dataList" />
    </div>

    <!--更多的弹框-->
    <div class="more-pop" v-if="moreFlag">
        <li @click="router.push({name: 'signIn'})"><img src="/src/assets/more/sign-in.svg"><span>每日签到</span></li>
        <li @click="router.push({name: 'myOrder'})"><img src="/src/assets/more/order-shopping.svg"><span>我的订单</span></li>
        <li @click="router.push({name: 'remindMessage'})"><img src="/src/assets/more/remind-message.svg"><span>消息提醒</span></li>
        <li @click="router.push({name: 'myCollect'})"><img src="/src/assets/more/my-collect.svg"><span>我的收藏</span></li>
        <li @click="router.push({name: 'myAddress'})"><img src="/src/assets/more/point-address.svg"><span>我的地址</span></li>
        <li @click="router.push({name: 'vip'})"><img src="/src/assets/more/vip.svg"><span>VIP会员</span></li>
    </div>

</div>
</template>
<script setup>
import { ref, onMounted, onBeforeUnmount } from "vue";
import ShopColumnList from "@/components/product/ShopColumnList.vue";
import router from "@/router/index";
import { truncateText } from "@/components/util/tools";


const currentIndex = ref(0);
const intervalTime = 3000;
let autoSlide;
let startX = 0;
let endX = 0;

const images = ref([
    { src: "/src/assets/lunbo/image1.jpeg", routeName: "shoppingActivity", remark: "1" },
    { src: "/src/assets/lunbo/image2.jpeg", routeName: "shoppingActivity", remark: "2" },
    { src: "/src/assets/lunbo/image3.jpeg", routeName: "shoppingActivity", remark: "3" },
]); // 替换为实际图片路径
const totalImages = ref(images.value.length);

const zhenxuan = ref({
    src: "/src/assets/lunbo/image1.jpeg",
    routeName: "shoppingActivity",
    remark: "甄选",
});
const haowu = ref({
    src: "/src/assets/lunbo/image2.jpeg",
    routeName: "shoppingActivity",
    remark: "好物",
});

const jingxuan = ref({
    src: "/src/assets/lunbo/image3.jpeg",
    routeName: "shoppingActivity",
    remark: "精选优品",
});
const shenghuo = ref({
    src: "/src/assets/lunbo/image2.jpeg",
    routeName: "shoppingActivity",
    remark: "生活百货",
});

const mallCar = () => {
    router.push({ name: 'shoppingCar' });
}

const serviceChat = () => {
    router.push({ name: 'serviceChat' });
}

const searchScan = () => {
    alert("打开扫一扫");
}

const getLocation = () => {
    alert("获取定位");
}

const searchBtn = () => {
    alert("直接搜索");
}

const searchInput = () => {
    router.push({ name: 'searchShopping' })
}

const dataList = ref([]);
const selectedIndicator = ref('精品优选');
const selectedChecked = (selectedTab) => {
    selectedIndicator.value = selectedTab;
    console.log("选择了不同的数据，当前选择是：", selectedTab);
    if (selectedTab === '精品优选') {
        dataList.value = [
            {
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7200.99,
                evalCount: 1000,
                evalRate: 100,
                id: 1
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 2
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 3
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 4
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 5
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 6
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 7
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 8
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 9
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 10
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 11
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 12
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 13
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 14
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 15
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 16
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 17
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 18
            },
        ];
    } else if (selectedTab === '生活百货') {
        dataList.value = [
            {
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7200.99,
                evalCount: 1000,
                evalRate: 100,
                id: 1
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 2
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 3
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 4
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 5
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 6
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 7
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 8
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 9
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 10
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 11
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 12
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 13
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 14
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 15
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 16
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 17
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 18
            },
        ];
    }
}

function carousel(image) {
    router.push({ name: image.routeName });
}

function zhenxuanFun(image) {
    router.push({ name: image.routeName, params: { moduleId: 123, moduleName: '甄选' } });
}

function haowuFun(image) {
    router.push({ name: image.routeName, params: { moduleId: 456, moduleName: '好物' } });
}

const menuTypes = ref([
    {
        typeName: '智能手表',
        typeIcon: '/src/assets/icons/menu.jpeg',
        typeId: 1,
        typePath: '/product/menuType',
        pathName: 'menuType'

    },{
        typeName: '智能手表',
        typeIcon: '/src/assets/icons/menu.jpeg',
        typeId: 1,
        typePath: '/product/menuType',
        pathName: 'menuType'

    },{
        typeName: '智能手表',
        typeIcon: '/src/assets/icons/menu.jpeg',
        typeId: 1,
        typePath: '/product/menuType',
        pathName: 'menuType'

    },{
        typeName: '智能手表',
        typeIcon: '/src/assets/icons/menu.jpeg',
        typeId: 1,
        typePath: '/product/menuType',
        pathName: 'menuType'

    },{
        typeName: '智能手表',
        typeIcon: '/src/assets/icons/menu.jpeg',
        typeId: 1,
        typePath: '/product/menuType',
        pathName: 'menuType'

    },{
        typeName: '智能手表',
        typeIcon: '/src/assets/icons/menu.jpeg',
        typeId: 1,
        typePath: '/product/menuType',
        pathName: 'menuType'

    },{
        typeName: '智能手表',
        typeIcon: '/src/assets/icons/menu.jpeg',
        typeId: 1,
        typePath: '/product/menuType',
        pathName: 'menuType'

    },{
        typeName: '智能手表',
        typeIcon: '/src/assets/icons/menu.jpeg',
        typeId: 1,
        typePath: '/product/menuType',
        pathName: 'menuType'

    },{
        typeName: '智能手表',
        typeIcon: '/src/assets/icons/menu.jpeg',
        typeId: 1,
        typePath: '/product/menuType',
        pathName: 'menuType'

    },{
        typeName: '更多分类',
        typeIcon: '/src/assets/icons/menu.jpeg',
        typeId: 1,
        typePath: '/product/menuType',
        pathName: 'menuType'

    }
]);

const jumpType = (menu) => {
    console.log("点击的分类：", menu);
    router.push({ name: menu.pathName });
}



function showNextImage() {
    currentIndex.value = (currentIndex.value + 1) % totalImages.value;
}
function showPreviousImage() {
    currentIndex.value = (currentIndex.value - 1 + totalImages.value) % totalImages.value;
}
function startAutoSlide() {
    autoSlide = setInterval(showNextImage, intervalTime);
}
function stopAutoSlide() {
    clearInterval(autoSlide);
}
function handleTouchStart(event) {
    stopAutoSlide(); // 停止自动轮播
    startX = "touches" in event ? event.touches[0].clientX : event.clientX;
}
function handleTouchMove(event) {
    endX = "touches" in event ? event.touches[0].clientX : event.clientX;
}
function handleTouchEnd() {
    if (startX > endX + 50) {
        showNextImage(); // 左滑，下一张
    } else if (startX < endX - 50) {
        showPreviousImage(); // 右滑，上一张
    }
    startAutoSlide(); // 滑动结束后重新启动自动轮播
}
function setCurrentIndex(index) {
    stopAutoSlide();
    currentIndex.value = index;
    startAutoSlide();
}

onMounted(() => {
    startAutoSlide();

    window.addEventListener('click', moreCloseClick);
    window.addEventListener('scroll', handleScroll);

    fetchData();
});
onBeforeUnmount(stopAutoSlide);

const moreFlag = ref(false);
const moreCloseClick = (event) => {
    moreFlag.value = false;
    if (event.target.alt === '更多') {
        moreFlag.value = true;
    }
}

const handleScroll = async () => {
    const scrollHeight = document.documentElement.scrollHeight;
    const scrollTop = document.documentElement.scrollTop;
    const clientHeight = document.documentElement.clientHeight;
    if (scrollHeight - scrollTop <= clientHeight) {
        console.log("首页的真的到底了");
        await fetchData();
    }
}

const isLoading = ref(false); // 控制加载状态的标志
const hasMore = ref(true); // 是否还有更多数据可以加载

// 模拟从后端加载数据的函数
const fetchData = async () => {
    if (isLoading.value || !hasMore.value) return;


    isLoading.value = true;

    // 模拟网络请求
    // const newItems = await new Promise(resolve => {
    //     console.log("模拟网络请求后端：", resolve);
    //     setTimeout(() => {
    //         const moreItems = Array.from({ length: 20 }, (_, index) => ({
    //             id: dataList.value.length + index,
    //             content: `内容${dataList.value.length + index}`
    //         }));
    //         resolve(moreItems);
    //     }, 1000);
    // });
    dataList.value = [
            {
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7200.99,
                evalCount: 1000,
                evalRate: 100,
                id: 1
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 2
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 3
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 4
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 5
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 6
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 7
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 8
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 9
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 10
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 11
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 12
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 13
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 14
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 15
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 16
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 17
            },{
                src: '/src/assets/lunbo/image1.jpeg',
                brandType: '电视',
                brandName: '小米',
                subBrandName: 'S Pro Mini LED',
                title: '120Hz超屏 这里是20个字以内的标题',
                content: '阿西吧',
                createDate: '2024-10-01',
                tags: ['120Hz超屏','性价比之王'],
                activePrice: 3200.00,
                price: 7100.99,
                evalCount: 1000,
                evalRate: 100,
                id: 18
            },
        ];

    // dataList.value.push(...newItems);
    isLoading.value = false;

    // 假设我们加载了50条数据后没有更多数据了
    if (dataList.value.length >= 50) {
        hasMore.value = false;
    }
}

const carNumber = ref(18);

</script>

<style scoped>
/* 头部 */
.header {
    width: 95%;
    position: fixed;
    z-index: 1000;
    background-color: #ffffff;
    top: 0;
    left: 0;
    right: 0;
    padding: 10px;
    margin: auto;
}
.index-header {
    height: 30px;
    width: 100%;
    /* 水平居中 */
    overflow: hidden;
    /* 防止内容溢出 */
    display: flex;
    flex-wrap: wrap;
}

.index-header .location {
    width: auto;
    height: 25px;
    text-align: left;
    cursor: pointer;
    float: left;
}
.index-header .location img {
    float: left;
    height: 25px;
    width: 25px;
}
.index-header .location label {
    font-size: 14px;
    float: left;
    padding-top: 4px;
    cursor: pointer;
}

.index-header .head-bar {
    float: right;
    text-align: right;
    height: 25px;
    margin: auto;
    margin-right: 0px;
}
.head-bar img {
    border-radius: 5px;
    background-color: transparent;
    cursor: pointer;
    width: 25px;
    height: 25px;
    margin: 0px 5px;
}

.search-container {
    display: flex;
    border: 1px solid #87ceeb;
    border-radius: 20px;
    /* 圆角 */
    overflow: hidden;
    /* 确保容器包裹内部元素 */
    background-color: aliceblue;
    width: 95%;
    height: 38px;
    margin: auto;
    margin-top: 5px;
}

.scan-btn {
    outline: none;
    height: 38px;
    padding-top: 6px;
    padding-left: 0px;
    padding-right: 0px;
    width: 13%;
}

.search-container label {
    margin: auto;
}

.search-input {
    border: none;
    /* 移除默认边框 */
    outline: none;
    /* 移除焦点时的轮廓 */
    background-color: #f0f0f0;
    /* 透明背景 */
    padding: 5px 10px;
    /* 内边距 */
    font-size: 14px;
    /* 字体大小 */
    width: auto;
}

.search-btn {
    border: 1px solid #f0f0f0;
    font-size: 14px;
    border-radius: 19px;
    margin: 1px;
    color: aliceblue;
    background-color: #87ceeb;
    padding: 1% 3%;
}
button:hover {
    border: #87ceeb;
}

.location-select {
    -webkit-appearance: none;
    /* 移除下拉框的默认样式 */
    -moz-appearance: none;
    appearance: none;
    cursor: pointer;
    background-color: aliceblue;
}

.search-input {
  flex-grow: 1;
  /* 占据剩余空间 */
  background-color: aliceblue;
  margin: auto;
}

.scan-btn {
  background-color: aliceblue;
  /* 浅灰色背景 */
  cursor: pointer;
  color: aliceblue;
}

.scan-btn img {
  margin: auto;
  width: 25px;
  height: 25px;
  font-size: 18px;
  /* 图标大小 */
  background-image: url("../../assets/icons/qr-code.png");
  background-repeat: no-repeat;
  background-position: right 2px center;
}

/* 功能菜单 */
.menu {
    text-align: center;
    margin: auto;
    width: 100%;
    height: 100%;
    margin-top: 85px;
    display: flex;
    flex-wrap: wrap;
}
.menu .menu-container {
  text-align: center; /* 让文本和图片居中显示 */
  width: 17%; /* 容器宽度，可以根据需要调整 */
  height: 15%;
  margin: auto; /* 水平居中 */
  margin: 2%;
  overflow: auto; /* 防止内容溢出 */
  background-color: transparent;
  cursor: pointer;
  margin-left: auto;
  margin-right: auto;
}
.menu .menu-image {
  width: 100%; /* 图片宽度，根据需要调整 */
  height: 100%;
  border-radius: 10px;
  display: block; /* 移除图片下方的默认间隙 */
}
.menu .menu-content {
  text-align: center; /* 让文本和图片居中显示 */
  width: 100%; /* 容器宽度，可以根据需要调整 */
  margin-top: 6px; /* 水平居中 */
  overflow: auto; /* 防止内容溢出 */
  cursor: pointer;
  font-size: 14px;
}

/* 活动模块*/
.adver {
  display: flex;
  margin-top: 10px;
}
/* 轮播 */
.adver .lunbo {
  width: 49%;
  height: 250px; /* 设定高度 */
  margin-right: 1%;
}
.carousel-container {
  height: 100%;
  position: relative;
  overflow: hidden;
}
.carousel {
  width: 100%;
  height: 100%;
  display: flex;
  transition: transform 0.3s ease-in-out;
  cursor: pointer;
  position: relative;
}
.carousel img {
  width: 100%;
  flex-shrink: 0;
  border-radius: 12px;
}
.dots {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
}
.dots span {
  height: 10px;
  width: 10px;
  background-color: #bbb;
  border-radius: 50%;
  margin: 0 5px;
  cursor: pointer;
}
.dots span.active {
  background: gray;
}

/* 活动 */
.huodong {
  width: 49%;
  margin-left: 1%;
  height: 250px;
}
.huodong .zhenxuan {
  height: 50%;
  height: auto;
  margin-bottom: 1%;
}
.huodong .zhenxuan img {
  height: 120px;
  width: 100%;
  border-radius: 12px;
}
.huodong .haowu {
  height: 50%;
  height: auto;
  margin-top: 1%;
}
.huodong .haowu img {
  height: 120px;
  width: 100%;
  border-radius: 12px;
}

/* 精选优品与生活百货*/
.life {
  height: 150px;
  display: flex;
  margin-top: 2%;
}
.life img {
  border-radius: 15px;
  height: 100%;
  width: 100%;
}
.life .jingxuan {
  height: 100%;
  margin: auto;
  margin-left: 0px;
  width: 49%;
}
.life .shenghuo {
  height: 100%;
  margin: auto;
  margin-right: 0px;
  width: 49%;
}

/* 商品导航 */
.shop-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  height: auto;
  width: 100%;
  margin-top: 10px;
}
.shop-nav .shop-title {
  text-align: center;
  margin: 1% auto;
  overflow: auto;
  width: 100%;
  position: relative;
}
.shop-title .clickable {
  text-align: center;
  cursor: pointer;
  position: relative;
  float: left;
  width: 50%;
  margin-top: 2%;
  border-radius: 5%;
  height: 100%;
  margin: auto;
}
.clickable .selected-indicator {
  width: 40%;
  height: 3px;
  display: block;
  border-radius: 10px;
  margin: auto;
  background-color: #87ceeb;
}

/*更多的弹框*/
.more-pop {
    position: fixed;
    z-index: 2000;
    width: 100px;
    border: 0px solid red;
    height: auto;
    background-color: white;
    top: 43px;
    right: 23px;
    border-radius: 12px;
    box-shadow: inset 0.1px 0.1px 2px rgba(0, 0, 0, 0.5);
    padding: 20px;
}
.more-pop li {
    list-style: none;
    margin: auto;
    display: flex;
    line-height: 40px;
    float: left;
}
.more-pop li img {
    width: 20px;
    height: 20px;
    margin: auto;
}
.more-pop li span {
    text-align: left;
    margin-left: 10px;
}
/*购物车数量*/
.car-number {
    position: absolute;
    font-size: 9px;
    border: 1px solid red;
    background-color: red;
    color: white;
    border-radius: 50px;
    margin-left: -12px;
    width: 13px;
    height: 13px;
    text-align: center;
}
</style>
